package com.woniuxy.joylifeforum.controller;

import com.woniuxy.common.entity.CenterUser;
import com.woniuxy.common.utils.JWTUtils;
import com.woniuxy.joylifeforum.service.UserCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
@RestController
public class UserCenterController {
    @Autowired
    private UserCenterService userCenterService;
    /*
       用户基本信息获取
        */
    @RequestMapping("/userMes")
    public Object userMes(HttpServletRequest request) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        System.out.println(userId);
        Map<String, Object> result = userCenterService.findUserMes(userId);
        result.put("code",200);
        result.put("mes","OK");
        return result;
    }
    /*
       用户信息修改
        */
    @RequestMapping("/userMesSubmit")
    public Object userMesSubmit(HttpServletRequest request,CenterUser user) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Map<String, Object> result = userCenterService.userMesSubmitService(userId, user);
        result.put("code",200);
        return result;
    }
}
